/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.util;

import org.lwjgl.util.vector.Vector3f;

/**
 *
 * @author Meanz
 */
public class VertexBuffer {

    private Vertex[] vertices;
    private int offset;

    public VertexBuffer() {
        vertices = new Vertex[0];
        offset = 0;
    }

    public void expand(int size) {
        Vertex[] temp = vertices;
        vertices = new Vertex[temp.length + size];
        System.arraycopy(temp, 0, vertices, 0, temp.length);
    }

    public void putVertex(float x, float y, float z) {
        vertices[offset++] = new Vertex(x, y, z);
    }

    public void putVertex(Vector3f vertex) {
        vertices[offset++] = new Vertex(vertex);
    }

    public void putVertex(Vertex vertex) {
        vertices[offset++] = vertex;
    }

    public void putVertices(Vector3f[] vertices) {
        for (int i = 0; i < vertices.length; i++) {
            putVertex(vertices[i]);
        }
    }

    public void putVertices(Vertex[] vertices) {
        for (int i = 0; i < vertices.length; i++) {
            putVertex(vertices[i]);
        }
    }

    public void clear() {
        vertices = new Vertex[0];
        offset = 0;
    }

    public Vertex[] getVertices() {
        return vertices;
    }

    public Vertex getVertex(int position) {
        if (position < 0 || position >= vertices.length) {
            return null;
        }
        return vertices[position];
    }

    public int size() {
        return vertices.length;
    }
}
